<script type="text/javascript">
$(function () {
	var pg = App.deploy.planFileEdit.ui, pp = pg.params;

	var frm = {
		code: pg.seek('code'),
		name: pg.seek('name'),
		sourcePath: pg.seek('sourcePath'),
		deployPath: pg.seek('deployPath'),
		packPath: pg.seek('packPath'),
		version: pg.seek('version'),
		type: pg.seek('type'),
		memo: pg.seek('memo')
	};

	function getValues() {
		return {
			id: pp.id,
			planId: pp.planId,
			code: frm.code.val(),
			name: frm.name.val(),
			sourcePath: frm.sourcePath.val(),
			deployPath: frm.deployPath.val(),
			packPath: frm.packPath.val(),
			version: frm.version.val(),
			type: pp.type || frm.type.val(),
			memo: frm.memo.val()
		};
	}

	function setValues(o) {
		pp.id = o.id;
		frm.code.val(o.code);
		frm.name.val(o.name);
		frm.sourcePath.val(o.sourcePath);
		frm.deployPath.val(o.deployPath);
		frm.packPath.val(o.packPath);
		frm.version.val(o.version);
		frm.type.val(o.type);
		frm.memo.val(o.memo);
	}

	function validate(p) {
		pg.find('.msg').html('');
		var x = App.validate, v = App.deploy.validator
			nm = pg.find('input[name=name] + .msg'),
			sm = pg.find('input[name=sourcePath] + .msg'),
			vm = pg.find('input[name=version] + .msg'),
			cm = pg.find('input[name=code] + .msg');

		return x(v.plan.code, p.code, cm) && 
			x(v.plan.name, p.name, nm) &&
			x(v.plan.sourcePath, p.sourcePath, sm) &&
			x(v.plan.version, p.version, vm);

	}

	pg.find('input').blur(function () {
		var pms = getValues();
		if (!validate(pms))
			return;
	});
	pg.seek('ok').click(function () {
		var pms = getValues();
		if (!validate(pms))
			return;
		$.post(App.deploy.ctx + '/plan/script/save.do', pms, function (rs) {
			var ro = mac.eval(rs);
			if (ro.success) {
				pg.callback(ro.data);
				pg.close();
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return false;
	});
	setValues(pp || {});

	pg.seek('close').click(function () {
		pg.close();
	});

	frm.type.mac('combo', {
		width: 302,
		boxWidth: 302,
		data: Cache.base.file.type
	}).val(pp.type || 0);

	if (pp.id) {
		/*  frm.code.attr('readonly', true); */
		// var w = mac.wait('loading');
		$.get(App.deploy.ctx + '/file/get.do', {
			id: pg.params.id
		}, function (rs) {
			var ro = mac.eval(rs);
			if (ro.success) {
				setValues(ro.data);
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
			// w.close();
		});
	} else {
		setValues(pp, '');
	}

	if (pp.type) {
		frm.type.disable();
	}
});
</script>
<div class="form">
	<div class="item">
		<span class="label">英文编号：</span> <input type="text" name="code"
												placeholder="请填入英文名字"/> <span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">名字：</span> <input type="text" name="name"
											  placeholder="请填入中文名字"/> <span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">源码路径：</span> <input type="text" name="sourcePath"
												placeholder="请填入源码路径"/> <span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">打包路径：</span> <input type="text" name="packPath"
												placeholder="请填入打包路径"/>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">部署路径：</span> <input type="text" name="deployPath"
												placeholder="请填入部署路径"/>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">类型：</span>
		<div class="combo" name="type"></div>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">版本号：</span>
		<input type="text" name="version" placeholder="请填入版本号"/> <span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">备忘录：</span>
		<textarea name="memo" placeholder="请填入memo"></textarea>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">&nbsp;</span>
		<div class="clear"></div>
	</div>
	<div class="bottom">
		<button name="ok" class="addBtn">确定</button>
		&nbsp;&nbsp;
		<button name="close" class="addBtn">取消</button>
	</div>
</div>